import 'package:fish_redux/fish_redux.dart';
import 'package:flutter/material.dart';
import '../../app_files.dart';

import 'action.dart';
import 'state.dart';
import 'widget/main_pie_widget.dart';
import 'model/main_view_model.dart';
import 'widget/main_item_widget.dart';

Widget buildView(
    MainViewState state, Dispatch dispatch, ViewService viewService) {
  double rpx =
      double.tryParse((ScreenUtil.screenWidthDp / 375).toStringAsFixed(2));

  ///用户界面
  Widget _userGasView() {
    final List myGas = [
      {'name': '户号管理', 'icon': IconFontConfig.HomeIcon_gasNoAdd},
      {'name': '安检记录', 'icon': IconFontConfig.HomeIcon_SafeOrder},
      {'name': '账单记录', 'icon': IconFontConfig.HomeIcon_gasOrder},
      // {'name': '购气充值', 'icon': IconFontConfig.HomeIcon_gasCharge},
    ];

    Widget _myGasItem() {
      List<Widget> widgets = myGas
          .map<Widget>(
            (e) => Expanded(
              child: InkWell(
                child: Container(
                  child: Column(
                    children: <Widget>[
                      Icon(
                        e['icon'],
                        color: ThemeConfig.mainColor,
                        size: 27,
                      ),
                      Padding(
                        padding: EdgeInsets.only(top: 13),
                        child: Text(
                          e['name'],
                          style: TextThemeConfig.MainViewItemStyle2,
                        ),
                      ),
                    ],
                  ),
                  color: Colors.white,
                ),
                onTap: () => dispatch(MainViewActionCreator.onTap(e['name'])),
              ),
            ),
          )
          .toList();
      widgets.add(Expanded(child: Container()));
      return Container(
        padding: EdgeInsets.only(bottom: 19),
        child: Row(
          children: widgets,
        ),
        decoration: BoxDecoration(
          border: Border(
            bottom: BorderSide(
              color: ThemeConfig.separeColor,
              width: 10,
            ),
          ),
        ),
      );
    }

    final List myBusiness = [
      {'name': '户号查询', 'icon': IconFontConfig.HomeIcon_gasNoSearch},
      {'name': '故障报修', 'icon': IconFontConfig.HomeIcon_SafeReport},
    ];

    Widget _myBusiness() {
      List<Widget> widgets = myBusiness
          .map<Widget>(
            (e) => Expanded(
              child: InkWell(
                child: Container(
                  child: Column(
                    children: <Widget>[
                      Icon(
                        e['icon'],
                        color: ThemeConfig.mainColor,
                        size: 27,
                      ),
                      Padding(
                        padding: EdgeInsets.only(top: 13),
                        child: Text(
                          e['name'],
                          style: TextThemeConfig.MainViewItemStyle2,
                        ),
                      ),
                    ],
                  ),
                  color: Colors.white,
                ),
                onTap: () => dispatch(MainViewActionCreator.onTap(e['name'])),
              ),
            ),
          )
          .toList();
      widgets.add(Expanded(child: Container()));
      widgets.add(Expanded(child: Container()));

      return Container(
        padding: EdgeInsets.only(bottom: 19),
        child: Row(
          children: widgets,
        ),
        decoration: BoxDecoration(
          border: Border(
            bottom: BorderSide(
              color: ThemeConfig.separeColor,
              width: 10,
            ),
          ),
        ),
      );
    }

    final List myServices = [
      {'name': '服务网点', 'icon': IconFontConfig.HomeIcon_gasStore},
      {'name': '燃气保险', 'icon': IconFontConfig.HomeIcon_Insurance},
    ];

    Widget _myServices() {
      List<Widget> widgets = myServices
          .map<Widget>(
            (e) => Expanded(
              child: InkWell(
                child: Container(
                  child: Column(
                    children: <Widget>[
                      Icon(
                        e['icon'],
                        color: ThemeConfig.mainColor,
                        size: 27,
                      ),
                      Padding(
                        padding: EdgeInsets.only(top: 13),
                        child: Text(
                          e['name'],
                          style: TextThemeConfig.MainViewItemStyle2,
                        ),
                      ),
                    ],
                  ),
                  color: Colors.white,
                ),
                onTap: () => dispatch(MainViewActionCreator.onTap(e['name'])),
              ),
            ),
          )
          .toList();
      widgets.add(Expanded(child: Container()));
      widgets.add(Expanded(child: Container()));
      return Container(
        padding: EdgeInsets.only(bottom: 19),
        child: Row(
          children: widgets,
        ),
      );
    }

    return Scaffold(
      backgroundColor: Colors.white,
      body: Column(
        children: [
          Stack(
            children: [
              Positioned(
                child: Container(
                  width: ScreenUtil.screenWidthDp,
                  color: ThemeConfig.separeColor,
                  child: Column(
                    children: [
                      Image.asset(
                        'images/main_bg.png',
                        width: ScreenUtil.screenWidthDp,
                        fit: BoxFit.fitWidth,
                      ),
                      SizedBox(
                        height: 120 * rpx,
                      )
                    ],
                  ),
                ),
                top: 0,
                left: 0,
                right: 0,
              ),
              Positioned(
                child: Container(
                  child: Center(
                    child: Text(
                      ThemeConfig.appTitle,
                      style: TextThemeConfig.Font18WithColorWhite,
                    ),
                  ),
                ),
                top: 17 * rpx + ScreenUtil.statusBarHeight,
                left: 0,
                right: 0,
              ),
              Container(
                width: ScreenUtil.screenWidthDp,
                child: viewService.buildComponent('banner'),
                margin: EdgeInsets.only(top: 58 + ScreenUtil.statusBarHeight),
                decoration: BoxDecoration(
                    border: Border(
                        bottom: BorderSide(
                  color: ThemeConfig.separeColor,
                  width: 10,
                ))),
              ),
            ],
          ),
          Expanded(
            child: SingleChildScrollView(
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: <Widget>[
                  Padding(
                    padding: EdgeInsets.only(left: 15, top: 15, bottom: 20),
                    child: Text(
                      '我的燃气',
                      style: TextThemeConfig.Font15WithColor22,
                    ),
                  ),
                  _myGasItem(),
                  Padding(
                    padding: EdgeInsets.only(left: 15, top: 15, bottom: 20),
                    child: Text(
                      '业务办理',
                      style: TextThemeConfig.Font15WithColor22,
                    ),
                  ),
                  _myBusiness(),
                  Padding(
                    padding: EdgeInsets.only(left: 15, top: 15, bottom: 20),
                    child: Text(
                      '便民服务',
                      style: TextThemeConfig.Font15WithColor22,
                    ),
                  ),
                  _myServices(),
                ],
              ),
            ),
          ),
        ],
      ),
    );
  }

  if (state.isGsUser == null) return MyLoadingWidget();

  if (state.isGsUser) return _userGasView();

  ///管理员界面
  Widget _topInfoWidget() => SliverToBoxAdapter(
        child: Container(
          height: 265,
          margin: EdgeInsets.only(bottom: 10),
          child: Stack(
            children: [
              Positioned(
                top: 0,
                left: 0,
                right: 0,
                child: Container(
                  height: 165,
                  color: ThemeConfig.mainColor,
                  child: Column(
                    children: [
                      Padding(
                        padding: EdgeInsets.only(top: 5, left: 15, right: 15),
                        child: Row(
                          children: [
                            Text(
                              (state.userInfo.isEngineer)
                                  ? (state.userInfo.isCustomer)
                                      ? '点火通气'
                                      : '工程统计'
                                  : (state.userInfo.isFixWorker)
                                      ? '维修统计'
                                      : (state.userInfo.isPatrolWorker)
                                          ? '巡检统计'
                                          : (state.checkLeaderType == 1)
                                              ? '安检统计'
                                              : '巡检统计',
                              style: TextThemeConfig.Font16WithWhite,
                            ),
                            Expanded(child: Container()),
                            Padding(
                              padding: EdgeInsets.only(right: 10),
                              child: Text(
                                (state.userInfo.isFixWorker) ? '今日维修' : (state.userInfo.isEngineer)
                                    ? '今日安装'
                                    : '今日已检',
                                style: TextThemeConfig.Font13WithColorWhite,
                              ),
                            ),
                            Text(
                              state.model.todayCheck,
                              style: TextThemeConfig.Font18WithColorWhite,
                            )
                          ],
                        ),
                      ),
                      (state.userInfo.isFixWorker || state.userInfo.isEngineer)
                          ? Expanded(
                        child: Container(
                          padding: EdgeInsets.only(
                              bottom: 45, right: 15, left: 15),
                          child: Row(
                            children: [
                              Expanded(
                                child: Column(
                                  mainAxisAlignment:
                                  MainAxisAlignment.center,
                                  children: [
                                    Padding(
                                      padding:
                                      EdgeInsets.only(bottom: 10),
                                      child: Text(
                                        state.model.newFixOrder
                                            .toString(),
                                        style: TextStyle(
                                          color: Colors.white,
                                          fontSize: 23,
                                          fontWeight: FontWeight.w500,
                                        ),
                                      ),
                                    ),
                                    Text(
                                      '新任务',
                                      style: TextThemeConfig
                                          .Font13WithColorWhite,
                                    ),
                                  ],
                                ),
                              ),
                              Expanded(
                                child: Column(
                                  mainAxisAlignment:
                                  MainAxisAlignment.center,
                                  children: [
                                    Padding(
                                      padding:
                                      EdgeInsets.only(bottom: 10),
                                      child: Text(
                                        state.model.unFixOrder.toString(),
                                        style: TextStyle(
                                          color: Colors.white,
                                          fontSize: 23,
                                          fontWeight: FontWeight.w500,
                                        ),
                                      ),
                                    ),
                                    Text(
                                      '已接任务',
                                      style: TextThemeConfig
                                          .Font13WithColorWhite,
                                    ),
                                  ],
                                ),
                              ),
                              Expanded(
                                child: Column(
                                  mainAxisAlignment:
                                  MainAxisAlignment.center,
                                  children: [
                                    Padding(
                                      padding:
                                      EdgeInsets.only(bottom: 10),
                                      child: Text(
                                        state.model.fixingOrder
                                            .toString(),
                                        style: TextStyle(
                                          color: Colors.white,
                                          fontSize: 23,
                                          fontWeight: FontWeight.w500,
                                        ),
                                      ),
                                    ),
                                    Text(
                                      state.userInfo.isEngineer
                                          ? '安装中'
                                          : '维修中',
                                      style: TextThemeConfig
                                          .Font13WithColorWhite,
                                    ),
                                  ],
                                ),
                              ),
                              Expanded(
                                child: Column(
                                  mainAxisAlignment:
                                  MainAxisAlignment.center,
                                  children: [
                                    Padding(
                                      padding:
                                      EdgeInsets.only(bottom: 10),
                                      child: Text(
                                        state.model.fixedOrder.toString(),
                                        style: TextStyle(
                                          color: Colors.white,
                                          fontSize: 23,
                                          fontWeight: FontWeight.w500,
                                        ),
                                      ),
                                    ),
                                    Text(
                                      state.userInfo.isEngineer
                                          ? '已安装'
                                          : '已维修',
                                      style: TextThemeConfig
                                          .Font13WithColorWhite,
                                    ),
                                  ],
                                ),
                              ),
                            ],
                          ),
                        ),
                      )
                          : (state.userInfo.isPatrolWorker ||
                                  (state.userInfo.isCheckLeader &&
                                      state.checkLeaderType == 2))
                              ? Expanded(
                                  child: Container(
                                    padding: EdgeInsets.only(
                                        bottom: 45, right: 15, left: 15),
                                    child: Row(
                                      children: [
                                        Expanded(
                                          child: Column(
                                            mainAxisAlignment:
                                                MainAxisAlignment.center,
                                            children: [
                                              Padding(
                                                padding:
                                                    EdgeInsets.only(bottom: 10),
                                                child: Text(
                                                  '${state.model.allCheck}',
                                                  style: TextStyle(
                                                    color: Colors.white,
                                                    fontSize: 23,
                                                    fontWeight: FontWeight.w500,
                                                  ),
                                                ),
                                              ),
                                              Text(
                                                '已巡检',
                                                style: TextThemeConfig
                                                    .Font13WithColorWhite,
                                              ),
                                            ],
                                          ),
                                        ),
                                        Expanded(
                                          child: Column(
                                            mainAxisAlignment:
                                                MainAxisAlignment.center,
                                            children: [
                                              Padding(
                                                padding:
                                                    EdgeInsets.only(bottom: 10),
                                                child: Text(
                                                  state.model.unCheck,
                                                  style: TextStyle(
                                                    color: Colors.white,
                                                    fontSize: 23,
                                                    fontWeight: FontWeight.w500,
                                                  ),
                                                ),
                                              ),
                                              Text(
                                                '待巡检',
                                                style: TextThemeConfig
                                                    .Font13WithColorWhite,
                                              ),
                                            ],
                                          ),
                                        ),
                                        Expanded(
                                          child: Column(
                                            mainAxisAlignment:
                                                MainAxisAlignment.center,
                                            children: [
                                              Padding(
                                                padding:
                                                    EdgeInsets.only(bottom: 10),
                                                child: Text(
                                                  state.model.communityNumber,
                                                  style: TextStyle(
                                                    color: Colors.white,
                                                    fontSize: 23,
                                                    fontWeight: FontWeight.w500,
                                                  ),
                                                ),
                                              ),
                                              Text(
                                                '覆盖片区',
                                                style: TextThemeConfig
                                                    .Font13WithColorWhite,
                                              ),
                                            ],
                                          ),
                                        ),
                                      ],
                                    ),
                                  ),
                                )
                              : Expanded(
                                  child: Container(
                                    padding: EdgeInsets.only(
                                        bottom: 45, right: 15, left: 15),
                                    child: Row(
                                      children: [
                                        Expanded(
                                          child: Column(
                                            mainAxisAlignment:
                                                MainAxisAlignment.center,
                                            children: [
                                              Padding(
                                                padding:
                                                    EdgeInsets.only(bottom: 10),
                                                child: Text(
                                                  '${state.model.allCheck}',
                                                  style: TextStyle(
                                                    color: Colors.white,
                                                    fontSize: 23,
                                                    fontWeight: FontWeight.w500,
                                                  ),
                                                ),
                                              ),
                                              Text(
                                                '已检户数',
                                                style: TextThemeConfig
                                                    .Font13WithColorWhite,
                                              ),
                                            ],
                                          ),
                                        ),
                                        Expanded(
                                          child: Column(
                                            mainAxisAlignment:
                                                MainAxisAlignment.center,
                                            children: [
                                              Padding(
                                                padding:
                                                    EdgeInsets.only(bottom: 10),
                                                child: Text(
                                                  state.model.unCheck,
                                                  style: TextStyle(
                                                    color: Colors.white,
                                                    fontSize: 23,
                                                    fontWeight: FontWeight.w500,
                                                  ),
                                                ),
                                              ),
                                              Text(
                                                '待检户数',
                                                style: TextThemeConfig
                                                    .Font13WithColorWhite,
                                              ),
                                            ],
                                          ),
                                        ),
                                        Expanded(
                                          child: Column(
                                            mainAxisAlignment:
                                                MainAxisAlignment.center,
                                            children: [
                                              Padding(
                                                padding:
                                                    EdgeInsets.only(bottom: 10),
                                                child: Text(
                                                  state.model.communityNumber,
                                                  style: TextStyle(
                                                    color: Colors.white,
                                                    fontSize: 23,
                                                    fontWeight: FontWeight.w500,
                                                  ),
                                                ),
                                              ),
                                              Text(
                                                '覆盖小区',
                                                style: TextThemeConfig
                                                    .Font13WithColorWhite,
                                              ),
                                            ],
                                          ),
                                        ),
                                      ],
                                    ),
                                  ),
                                ),
                    ],
                  ),
                ),
              ),
              Positioned(
                top: 120,
                left: 15,
                right: 15,
                child: Container(
                  height: 145,
                  padding: EdgeInsets.only(right: 38),
                  decoration: BoxDecoration(
                    color: Colors.white,
                    borderRadius: BorderRadius.all(Radius.circular(4)),
                  ),
                  child: MainViewPieWidget(state.model, state.type),
                ),
              )
            ],
          ),
        ),
      );

  List<String> sortTitles = ['全部', '待安检', '安检中', '已完成'];
  List<String> customerTitles = ['新任务',
    '已接任务','隐患待排查','安装中','已安装', ];
  List<String> fixTitles = [
    '新任务',
    '已接任务',
    state.userInfo.isEngineer ? '安装中' : '维修中',
    state.userInfo.isEngineer ? '已安装' : '已维修'
  ];
  List<String> patrolTitles = ['全部', '待巡检', '巡检中', '已完成'];

  Widget _sortWidget() {
    List<Widget> items = [];
    if (state.userInfo.isCheckLeader) {
      return CustomSliverHeader(
        maxHeight: 45,
        minHeight: 45,
        child: Container(
          width: double.infinity,
          color: Colors.white,
          height: 45,
          margin: EdgeInsets.only(bottom: 4),
          padding: EdgeInsets.only(left: 12),
          child: Align(
            child: Text(
              state.checkLeaderType == 1 ? '安检员统计' : '巡检员统计',
              style: TextThemeConfig.Font16BoldWithColor22,
            ),
            alignment: Alignment.centerLeft,
          ),
        ),
      );
    } else {
      List<String> list = state.userInfo.isCheckWorker
          ? sortTitles
          : state.userInfo.isPatrolWorker ? patrolTitles : state.userInfo.isCustomer ? customerTitles: fixTitles;
      items = list.map<Widget>((e) {
        int index = list.indexOf(e);
        return Expanded(
          child: Container(
            color:
                state.sortIndex == index ? ThemeConfig.mainColor : Colors.white,
            child: InkWell(
              child: Align(
                child: Text(
                  e,
                  style: TextStyle(
                    color: state.sortIndex == index
                        ? Colors.white
                        : ThemeConfig.blackColor,
                    fontSize: 14,
                    fontWeight: FontWeight.w500,
                  ),
                ),
              ),
              onTap: () => dispatch(MainViewActionCreator.onTapSort(index)),
            ),
          ),
        );
      }).toList();
    }

    return CustomSliverHeader(
      maxHeight: 60,
      minHeight: 60,
      child: Container(
        width: double.infinity,
        color: Colors.white,
        margin: EdgeInsets.only(bottom: 10),
        child: Row(
          children: items,
        ),
      ),
    );
  }

  Widget installItemBuilder(BuildContext context, int index) {
    InstallItemModel item = state.items[index];
    return MainItemWidget.installItemBuilder(context, item);
  }

  Widget leaderBuilder(BuildContext context, int index) {
    LeaderItemModel item = state.items[index];
    return MainItemWidget.leaderBuilder(context, item);
  }

  Widget safeBuilder(BuildContext context, int index) {
    CommunityItemModel item = state.items[index];
    return MainItemWidget.safeBuilder(context, item);
  }

  Widget patrolBuilder(BuildContext context, int index) {
    PatrolAreaModel item = state.items[index];
    return MainItemWidget.patrolBuilder(context, item);
  }

  Widget fixBuilder(BuildContext context, int index) {
    if (index == state.items.length) {
      return Container(
        child: Center(
            child: MyInkWellWidget(
              child: Padding(
                padding: EdgeInsets.only(top: 12, bottom: 12),
                child: Text(
                  '查看更多',
                  style: TextThemeConfig.Font15WithMainColor,
                ),
              ),
              onTap: () => CommonUtils.pushRoute(
                  context, RoutePath.engineerListView,
                  arguments: {'sort': state.sortIndex, 'type': state.type}),
            )),
      );
    }
    FixListItemModel item = state.items[index];
    if (state.multipleSelect)
      return Row(
        children: [
          GestureDetector(
            child: Container(
              height: 130,
              width: 35,
              child: Padding(
                padding: EdgeInsets.only(left: 15),
                child: Image.asset(
                  state.selectItems.contains(item)
                      ? 'images/cricle_select.png'
                      : 'images/circle.png',
                  fit: BoxFit.fitWidth,
                ),
              ),
            ),
            onTap: () => dispatch(MainViewActionCreator.onSelectOne(item)),
            behavior: HitTestBehavior.translucent,
          ),
          Container(
            child: MainItemWidget.fixBuilder(context, item,
                onTap: state.multipleSelect
                    ? (item) =>
                        dispatch(MainViewActionCreator.onSelectOne(item))
                    : null),
            width: ScreenUtil.screenWidthDp,
          )
        ],
      );
    return state.userInfo.isEngineer
        ? MainItemWidget.engineerBuilder(context, item)
        : MainItemWidget.fixBuilder(context, item);
  }

  Widget _itemWidget() {
    if (state.itemLoaded == false) {
      return SliverFillRemaining(
        child: Align(
          child: MyLoadingWidget(),
        ),
      );
    } else if (state.items == null || state.items.length == 0)
      return SliverToBoxAdapter(
        child: MyEmptyItemWidget(),
      );
    int count = state.items.length;
    if (state.type == 2 || state.type == 5) {
      count += 1;
    }
    return SliverList(
      delegate: SliverChildBuilderDelegate(
        state.type == 0
            ? leaderBuilder
            : state.type == 1
                ? safeBuilder
                : state.type == 3 ? patrolBuilder : fixBuilder,
        childCount: count,
      ),
    );
  }

  Widget _countLeaderWidget() {
    CountLeaderModel model = state.countModel;
    Widget _newBossTodayCount() {
      double total = double.tryParse(model.totalMoney) ?? 0.0;
      List dataList = [
        {
          'icon': 'b_wx.png',
          'name': '微信',
          'money': model.wxMoney,
          'count': model.wxCount,
          'ratio': total == 0.0
              ? 0.0
              : (double.tryParse(model.wxMoney) ?? 0.0) / total,
        },
        {
          'icon': 'b_zfb.png',
          'name': '支付宝',
          'money': model.zfbMoney,
          'count': model.zfbCount,
          'ratio': total == 0.0
              ? 0.0
              : (double.tryParse(model.zfbMoney) ?? 0.0) / total,
        },
        {
          'icon': 'b_official.png',
          'name': '公众号',
          'money': model.officialMoney,
          'count': model.officialCount,
          'ratio': total == 0.0
              ? 0.0
              : (double.tryParse(model.officialMoney) ?? 0.0) / total,
        },
        // {
        //   'icon': 'b_APP.png',
        //   'name': 'APP',
        //   'money': model.appMoney,
        //   'count': model.appCount,
        //   'ratio':
        //       total == 0.0 ? 0.0 : (double.tryParse(model.appMoney) ?? 0.0) / total,
        // },
        {
          'icon': 'b_bank.png',
          'name': '掌上银行',
          'money': model.nhMoney,
          'count': model.nhCount,
          'ratio': total == 0.0
              ? 0.0
              : (double.tryParse(model.nhMoney) ?? 0.0) / total,
        },
        {
          'icon': 'b_cash.png',
          'name': '现金',
          'money': model.cashMoney,
          'count': model.cashCount,
          'ratio': total == 0.0
              ? 0.0
              : (double.tryParse(model.cashMoney) ?? 0.0) / total,
        },
      ];
      dataList.sort((a, b) {
        double aValue = a['ratio'];
        double bValue = b['ratio'];
        return bValue.compareTo(aValue);
      });
      return Container(
        padding: EdgeInsets.only(left: 15, right: 15),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: dataList
              .map<Widget>((e) => Container(
                    padding: EdgeInsets.only(top: 5, bottom: 15),
                    child: Row(
                      children: [
                        Image.asset('images/${e['icon']}'),
                        Padding(padding: EdgeInsets.only(left: 10)),
                        Expanded(
                          child: Column(
                            // mainAxisAlignment: MainAxisAlignment.center,
                            children: [
                              Row(
                                children: [
                                  Text(
                                    '${e['name']} ${(e['ratio'] * 100).toStringAsFixed(0)}%',
                                    style: TextThemeConfig.Font13WithColor99,
                                  ),
                                  Expanded(child: Container()),
                                  Text(
                                    e['money'],
                                    style: TextThemeConfig.Font14WithColor22,
                                  ),
                                  Padding(padding: EdgeInsets.only(left: 5)),
                                  Text(
                                    '${e['count']}笔',
                                    style: TextThemeConfig.Font13WithColor99,
                                  ),
                                ],
                              ),
                              Padding(
                                padding: EdgeInsets.only(top: 10, bottom: 2),
                                child: Row(
                                  children: [
                                    Expanded(
                                      child: MyProgressWidget(
                                        height: 6,
                                        value: e['ratio'],
                                        color: Color(0xff4D81EF),
                                        backColor: Color(0xfff8f8f8),
                                      ),
                                    )
                                  ],
                                ),
                              ),
                            ],
                          ),
                        ),
                      ],
                    ),
                  ))
              .toList(),
        ),
      );
    }

    return CustomRefreshList(
      whiteBg: false,
      currentPage: state.currentPage,
      refreshController: state.refreshController,
      onRefresh: (_) => dispatch(MainViewActionCreator.onRefresh()),
      child: Column(
        children: [
          Stack(
            children: [
              Container(
                child: Column(
                  children: [
                    Image.asset(
                      'images/big_bg.png',
                      width: double.infinity,
                      fit: BoxFit.fitWidth,
                    ),
                    Container(
                      height: 50 * rpx,
                    ),
                  ],
                ),
              ),
              Positioned(
                child: Container(
                  padding: EdgeInsets.only(top: 18),
                  child: Column(
                    children: [
                      Row(
                        children: [
                          Expanded(
                            child: Column(
                              children: [
                                Text(
                                  '￥${model.totalMoney}',
                                  maxLines: 1,
                                  style: TextStyle(
                                    color: Colors.white,
                                    fontSize: 21,
                                    fontWeight: FontWeight.w600,
                                  ),
                                ),
                                Padding(
                                  padding: EdgeInsets.only(top: 4, bottom: 20),
                                  child: Text(
                                    '今日账单',
                                    style: TextStyle(
                                      color: Colors.white,
                                      fontSize: 13,
                                      fontWeight: FontWeight.w500,
                                    ),
                                  ),
                                ),
                              ],
                            ),
                          ),
                        ],
                      ),
                      Row(
                        children: [
                          Expanded(
                            child: Align(
                              child: Column(
                                children: [
                                  Text(
                                    '￥${model.monthMoney}',
                                    maxLines: 1,
                                    style: TextStyle(
                                      color: Colors.white,
                                      fontSize: 18,
                                      fontWeight: FontWeight.w600,
                                    ),
                                  ),
                                  Padding(
                                    padding: EdgeInsets.only(top: 4),
                                    child: Text(
                                      '本月账单',
                                      style: TextStyle(
                                        color: Colors.white,
                                        fontSize: 13,
                                        fontWeight: FontWeight.w500,
                                      ),
                                    ),
                                  ),
                                ],
                              ),
                            ),
                          ),
                          Container(
                            width: 1,
                            height: 24,
                            color: Color(0xffACC6FC),
                          ),
                          Expanded(
                            child: Column(
                              children: [
                                Text(
                                  '￥${model.yearMoney}',
                                  maxLines: 1,
                                  style: TextStyle(
                                    color: Colors.white,
                                    fontSize: 18,
                                    fontWeight: FontWeight.w600,
                                  ),
                                ),
                                Padding(
                                  padding: EdgeInsets.only(top: 4),
                                  child: Text(
                                    '本年账单',
                                    style: TextStyle(
                                      color: Colors.white,
                                      fontSize: 13,
                                      fontWeight: FontWeight.w500,
                                    ),
                                  ),
                                ),
                              ],
                            ),
                          ),
                        ],
                      ),
                      Container(
                        width: double.infinity,
                        decoration: BoxDecoration(
                          color: Colors.white,
                          borderRadius: BorderRadius.all(Radius.circular(4)),
                        ),
                        padding: EdgeInsets.only(top: 12),
                        margin: EdgeInsets.only(top: 20, left: 15, right: 15),
                        child: Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: [
                            Padding(
                              padding: EdgeInsets.only(left: 15, bottom: 5),
                              child: Text(
                                '日账单统计',
                                style: TextThemeConfig.Font16WithColorBold22,
                              ),
                            ),
                            _newBossTodayCount(),
                          ],
                        ),
                      ),
                    ],
                  ),
                ),
              ),
            ],
          ),

          ///用户统计
          Container(
            width: double.infinity,
            margin: EdgeInsets.only(left: 15, right: 15, top: 10, bottom: 10),
            decoration: BoxDecoration(
              color: Colors.white,
              borderRadius: BorderRadius.all(Radius.circular(4)),
            ),
            padding: EdgeInsets.only(top: 12, bottom: 12),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Padding(
                  padding: EdgeInsets.only(left: 15, bottom: 10),
                  child: Text(
                    '用户统计',
                    style: TextThemeConfig.Font16WithColorBold22,
                  ),
                ),
                Container(
                  height: 170,
                  // margin: EdgeInsets.only(left: 4, right: 4),
                  child: UserNumberPieWidget(state.countModel, false),
                ),
                Container(
                  height: 170,
                  // margin: EdgeInsets.only(left: 4, right: 4),
                  child: UserNumberPieWidget(state.countModel, true),
                ),
              ],
            ),
          ),

          ///安检统计
          Container(
            width: double.infinity,
            decoration: BoxDecoration(
              color: Colors.white,
              borderRadius: BorderRadius.all(Radius.circular(4)),
            ),
            padding: EdgeInsets.only(top: 12, bottom: 12),
            margin: EdgeInsets.only(left: 15, right: 15, bottom: 10),
            child: Column(
              children: [
                Padding(
                  padding: EdgeInsets.only(left: 15, right: 15, bottom: 10),
                  child: Row(
                    children: [
                      Text(
                        '安检统计',
                        style: TextThemeConfig.Font16WithColorBold22,
                      ),
                      Expanded(child: Container()),
                      Padding(
                        padding: EdgeInsets.only(right: 10),
                        child: Text(
                          '今日已检',
                          style: TextThemeConfig.Font13WithColor99,
                        ),
                      ),
                      Text(
                        model.safeModel.todayCheck,
                        style: TextThemeConfig.Font18WithBoldColor22,
                      )
                    ],
                  ),
                ),
                Row(
                  children: [
                    Expanded(
                      child: Column(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          Padding(
                            padding: EdgeInsets.only(bottom: 4),
                            child: Text(
                              '${model.safeModel.allCheck}',
                              style: TextThemeConfig.Font21WithColor22,
                            ),
                          ),
                          Text(
                            '已检户数',
                            style: TextThemeConfig.Font13WithColor99,
                          ),
                        ],
                      ),
                    ),
                    Expanded(
                      child: Column(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          Padding(
                            padding: EdgeInsets.only(bottom: 4),
                            child: Text(
                              model.safeModel.unCheck,
                              style: TextThemeConfig.Font21WithColor22,
                            ),
                          ),
                          Text(
                            '待检户数',
                            style: TextThemeConfig.Font13WithColor99,
                          ),
                        ],
                      ),
                    ),
                    Expanded(
                      child: Column(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          Padding(
                            padding: EdgeInsets.only(bottom: 4),
                            child: Text(
                              model.safeModel.communityNumber,
                              style: TextThemeConfig.Font21WithColor22,
                            ),
                          ),
                          Text(
                            '覆盖小区',
                            style: TextThemeConfig.Font13WithColor99,
                          ),
                        ],
                      ),
                    ),
                  ],
                ),
                Container(
                  height: 145,
                  margin: EdgeInsets.only(left: 15, right: 15),
                  padding: EdgeInsets.only(right: 38),
                  child: MainViewPieWidget(model.safeModel, 1),
                ),
                Padding(
                  padding: EdgeInsets.only(top: 0, left: 23),
                  child: Row(
                    children: [
                      Text(
                        '安检率',
                        style: TextThemeConfig.Font14WithColor66,
                      ),
                      Expanded(
                        child: Container(
                          padding: EdgeInsets.symmetric(horizontal: 10),
                          child: MyProgressWidget(
                            value: model.safeModel.totalCheck == 0
                                ? 0
                                : model.safeModel.allCheck /
                                    model.safeModel.totalCheck,
                            color: Color(0xff20E188),
                          ),
                        ),
                      ),
                      Padding(
                        padding: EdgeInsets.only(right: 20),
                        child: Text(
                          model.safeModel.safeScale,
                          style: TextThemeConfig.Font14WithColor22,
                        ),
                      ),
                    ],
                  ),
                ),
                Padding(
                  padding: EdgeInsets.only(top: 14, left: 23),
                  child: Row(
                    children: [
                      Text(
                        '正常率',
                        style: TextThemeConfig.Font14WithColor66,
                      ),
                      Expanded(
                          child: Container(
                        padding: EdgeInsets.symmetric(horizontal: 10),
                        child: MyProgressWidget(
                          value: model.safeModel.allCheck == 0
                              ? 0
                              : model.safeModel.normalNumber /
                                  model.safeModel.allCheck,
                          color: Color(0xff20E188),
                        ),
                      )),
                      Padding(
                        padding: EdgeInsets.only(right: 20),
                        child: Text(
                          model.safeModel.normalScale,
                          style: TextThemeConfig.Font14WithColor22,
                        ),
                      ),
                    ],
                  ),
                ),
              ],
            ),
          ),

          ///巡检统计
          Container(
            width: double.infinity,
            decoration: BoxDecoration(
              color: Colors.white,
              borderRadius: BorderRadius.all(Radius.circular(4)),
            ),
            padding: EdgeInsets.only(top: 12, bottom: 12),
            margin: EdgeInsets.only(left: 15, right: 15, bottom: 10),
            child: Column(
              children: [
                Padding(
                  padding: EdgeInsets.only(left: 15, right: 15, bottom: 10),
                  child: Row(
                    children: [
                      Text(
                        '巡检统计',
                        style: TextThemeConfig.Font16WithColorBold22,
                      ),
                      Expanded(child: Container()),
                      Padding(
                        padding: EdgeInsets.only(right: 10),
                        child: Text(
                          '今日已检',
                          style: TextThemeConfig.Font13WithColor99,
                        ),
                      ),
                      Text(
                        model.patrolModel.todayCheck,
                        style: TextThemeConfig.Font18WithBoldColor22,
                      )
                    ],
                  ),
                ),
                Row(
                  children: [
                    Expanded(
                      child: Column(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          Padding(
                            padding: EdgeInsets.only(bottom: 4),
                            child: Text(
                              '${model.patrolModel.allCheck}',
                              style: TextThemeConfig.Font21WithColor22,
                            ),
                          ),
                          Text(
                            '已检管点',
                            style: TextThemeConfig.Font13WithColor99,
                          ),
                        ],
                      ),
                    ),
                    Expanded(
                      child: Column(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          Padding(
                            padding: EdgeInsets.only(bottom: 4),
                            child: Text(
                              model.patrolModel.unCheck,
                              style: TextThemeConfig.Font21WithColor22,
                            ),
                          ),
                          Text(
                            '待检管点',
                            style: TextThemeConfig.Font13WithColor99,
                          ),
                        ],
                      ),
                    ),
                    Expanded(
                      child: Column(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          Padding(
                            padding: EdgeInsets.only(bottom: 4),
                            child: Text(
                              model.patrolModel.communityNumber,
                              style: TextThemeConfig.Font21WithColor22,
                            ),
                          ),
                          Text(
                            '覆盖片区',
                            style: TextThemeConfig.Font13WithColor99,
                          ),
                        ],
                      ),
                    ),
                  ],
                ),
                Container(
                  height: 145,
                  margin: EdgeInsets.only(left: 15, right: 15),
                  padding: EdgeInsets.only(right: 38),
                  child: MainViewPieWidget(model.patrolModel, 3),
                ),
                Padding(
                  padding: EdgeInsets.only(top: 0, left: 23),
                  child: Row(
                    children: [
                      Text(
                        '巡检率',
                        style: TextThemeConfig.Font14WithColor66,
                      ),
                      Expanded(
                        child: Container(
                          padding: EdgeInsets.symmetric(horizontal: 10),
                          child: MyProgressWidget(
                            value: model.patrolModel.totalCheck == 0
                                ? 0
                                : model.patrolModel.allCheck /
                                    model.patrolModel.totalCheck,
                            color: Color(0xff20E188),
                          ),
                        ),
                      ),
                      Padding(
                        padding: EdgeInsets.only(right: 20),
                        child: Text(
                          model.patrolModel.safeScale,
                          style: TextThemeConfig.Font14WithColor22,
                        ),
                      ),
                    ],
                  ),
                ),
                Padding(
                  padding: EdgeInsets.only(top: 14, left: 23),
                  child: Row(
                    children: [
                      Text(
                        '正常率',
                        style: TextThemeConfig.Font14WithColor66,
                      ),
                      Expanded(
                          child: Container(
                        padding: EdgeInsets.symmetric(horizontal: 10),
                        child: MyProgressWidget(
                          value: model.patrolModel.allCheck == 0
                              ? 0
                              : model.patrolModel.normalNumber /
                                  model.patrolModel.allCheck,
                          color: Color(0xff20E188),
                        ),
                      )),
                      Padding(
                        padding: EdgeInsets.only(right: 20),
                        child: Text(
                          model.patrolModel.normalScale,
                          style: TextThemeConfig.Font14WithColor22,
                        ),
                      ),
                    ],
                  ),
                ),
              ],
            ),
          ),

          ///维修统计
          Container(
            width: double.infinity,
            decoration: BoxDecoration(
              color: Colors.white,
              borderRadius: BorderRadius.all(Radius.circular(4)),
            ),
            margin: EdgeInsets.only(left: 15, right: 15, bottom: 25),
            padding: EdgeInsets.only(top: 12, bottom: 12),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Padding(
                  padding: EdgeInsets.only(left: 15, right: 15, bottom: 10),
                  child: Row(
                    children: [
                      Text(
                        '维修统计',
                        style: TextThemeConfig.Font16WithColorBold22,
                      ),
                      Expanded(child: Container()),
                      Padding(
                        padding: EdgeInsets.only(right: 10),
                        child: Text(
                          '今日维修',
                          style: TextThemeConfig.Font13WithColor99,
                        ),
                      ),
                      Text(
                        model.fixModel.todayTotal,
                        style: TextThemeConfig.Font18WithBoldColor22,
                      )
                    ],
                  ),
                ),
                Row(
                  children: [
                    Expanded(
                      child: Column(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          Padding(
                            padding: EdgeInsets.only(bottom: 4),
                            child: Text(
                              '${model.fixModel.totalNumber}',
                              style: TextThemeConfig.Font21WithColor22,
                            ),
                          ),
                          Text(
                            '总维修订单',
                            style: TextThemeConfig.Font13WithColor99,
                          ),
                        ],
                      ),
                    ),
                    Expanded(
                      child: Column(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          Padding(
                            padding: EdgeInsets.only(bottom: 4),
                            child: Text(
                              '${model.fixModel.newTotal}',
                              style: TextThemeConfig.Font21WithColor22,
                            ),
                          ),
                          Text(
                            '未派单数',
                            style: TextThemeConfig.Font13WithColor99,
                          ),
                        ],
                      ),
                    ),
                    Expanded(
                      child: Column(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          Padding(
                            padding: EdgeInsets.only(bottom: 4),
                            child: Text(
                              '${model.fixModel.sendTotal}',
                              style: TextThemeConfig.Font21WithColor22,
                            ),
                          ),
                          Text(
                            '已派单数',
                            style: TextThemeConfig.Font13WithColor99,
                          ),
                        ],
                      ),
                    ),
                    Expanded(
                      child: Column(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          Padding(
                            padding: EdgeInsets.only(bottom: 4),
                            child: Text(
                              '${model.fixModel.fixedTotal}',
                              style: TextThemeConfig.Font21WithColor22,
                            ),
                          ),
                          Text(
                            '已维修数',
                            style: TextThemeConfig.Font13WithColor99,
                          ),
                        ],
                      ),
                    ),
                  ],
                ),
                Padding(
                  padding: EdgeInsets.only(top: 10, left: 23),
                  child: Row(
                    children: [
                      Text(
                        '接单率',
                        style: TextThemeConfig.Font14WithColor66,
                      ),
                      Expanded(
                        child: Container(
                          padding: EdgeInsets.symmetric(horizontal: 10),
                          child: MyProgressWidget(
                            value: double.tryParse(model.fixModel.receiveRate) /
                                    100 ??
                                0,
                            color: Color(0xff20E188),
                          ),
                        ),
                      ),
                      Padding(
                        padding: EdgeInsets.only(right: 20),
                        child: Text(
                          model.fixModel.getScale,
                          style: TextThemeConfig.Font14WithColor22,
                        ),
                      ),
                    ],
                  ),
                ),
                Padding(
                  padding: EdgeInsets.only(top: 14, left: 23),
                  child: Row(
                    children: [
                      Text(
                        '维修率',
                        style: TextThemeConfig.Font14WithColor66,
                      ),
                      Expanded(
                        child: Container(
                          padding: EdgeInsets.symmetric(horizontal: 10),
                          child: MyProgressWidget(
                            value:
                                double.tryParse(model.fixModel.fixRate) / 100 ??
                                    0,
                            color: Color(0xff20E188),
                          ),
                        ),
                      ),
                      Padding(
                        padding: EdgeInsets.only(right: 20),
                        child: Text(
                          model.fixModel.fixScale,
                          style: TextThemeConfig.Font14WithColor22,
                        ),
                      ),
                    ],
                  ),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }

  Widget _installWidget() {
    return Container(
      child: Column(
        children: [
          Container(
            color: ThemeConfig.mainColor,
            child: MySearchWidget(
              searchText: '搜索',
              type: 4,
              heroTag: 'MainSearch',
            ),
          ),
          Expanded(
            child: CustomRefreshList(
              whiteBg: false,
              currentPage: state.currentPage,
              refreshController: state.refreshController,
              onRefresh: (_) => dispatch(MainViewActionCreator.onRefresh()),
              onLoading: (_, page) =>
                  dispatch(MainViewActionCreator.onLoad(page)),
              child: CustomScrollView(
                physics: NeverScrollableScrollPhysics(),
                slivers: [
                  SliverToBoxAdapter(
                    child: Container(
                      padding: EdgeInsets.only(top: 20, bottom: 30),
                      margin: EdgeInsets.only(bottom: 10),
                      color: ThemeConfig.mainColor,
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          Padding(
                            padding: EdgeInsets.only(left: 15, bottom: 20),
                            child: Text(
                              '报装统计',
                              style: TextThemeConfig.Font16WithWhite,
                            ),
                          ),
                          Row(
                            children: [
                              Expanded(
                                child: Column(
                                  children: [
                                    Text(
                                      state.installModel.totalMoney,
                                      style:
                                          TextThemeConfig.Font22WithColorWhite,
                                    ),
                                    Padding(padding: EdgeInsets.only(top: 4)),
                                    Text(
                                      '已收金额(元)',
                                      style:
                                          TextThemeConfig.Font14WithColorWhite,
                                    ),
                                  ],
                                ),
                              ),
                              Expanded(
                                child: Column(
                                  children: [
                                    Text(
                                      state.installModel.totalNumber,
                                      style:
                                          TextThemeConfig.Font22WithColorWhite,
                                    ),
                                    Padding(padding: EdgeInsets.only(top: 4)),
                                    Text(
                                      '报装户数',
                                      style:
                                          TextThemeConfig.Font14WithColorWhite,
                                    ),
                                  ],
                                ),
                              ),
                              Expanded(
                                child: Column(
                                  children: [
                                    Text(
                                      state.installModel.communityNumber,
                                      style:
                                          TextThemeConfig.Font22WithColorWhite,
                                    ),
                                    Padding(padding: EdgeInsets.only(top: 4)),
                                    Text(
                                      '报装小区',
                                      style:
                                          TextThemeConfig.Font14WithColorWhite,
                                    ),
                                  ],
                                ),
                              ),
                            ],
                          ),
                        ],
                      ),
                    ),
                  ),
                  state.items == null
                      ? SliverToBoxAdapter(
                          child: MyLoadingWidget(),
                        )
                      : state.items.length == 0
                          ? SliverToBoxAdapter(
                              child: MyEmptyItemWidget(
                                image: 'images/empty_install.png',
                                desc: '暂无报装用户信息...',
                              ),
                            )
                          : SliverList(
                              delegate: SliverChildBuilderDelegate(
                                installItemBuilder,
                                childCount: state.items.length,
                              ),
                            )
                ],
              ),
            ),
          ),
        ],
      ),
    );
  }

  String _title() {
    if (state.userInfo.isCheckWorker) return '安检任务';
    if (state.userInfo.isPatrolWorker) return '巡检任务';
    if (state.userInfo.isFixWorker) return '维修任务';
    if (state.userInfo.isCustomer) return '点火通气';
    if (state.userInfo.isEngineer) return '工程统计';
    if (state.userInfo.isInstallWorker) return '报装统计';
    if (state.userInfo.isCountLeader) return '营业统计';
    if (state.userInfo.isCheckLeader)
      return state.checkLeaderType == 1 ? '安检统计' : '巡检统计';
    return '';
  }

  List<Widget> _actions() {
    if (state.userInfo.isFixWorker)
      return [
        // GestureDetector(
        //   child: Container(
        //     width: 80,
        //     height: 80,
        //     child: Align(
        //       child: Image.asset('images/ic_change.png'),
        //     ),
        //   ),
        //   onTap: () => CommonUtils.pushRoute(
        //       viewService.context, RoutePath.planListView),
        //   behavior: HitTestBehavior.translucent,
        // )
      ];
    if (state.userInfo.isCheckWorker) {
      return [
        GestureDetector(
          child: Container(
            width: 80,
            height: 80,
            child: Align(
              child: Image.asset('images/ic_change.png'),
            ),
          ),
          onTap: () => CommonUtils.pushRoute(
              viewService.context, RoutePath.planListView),
          behavior: HitTestBehavior.translucent,
        )
      ];
    }
    if (state.userInfo.isPatrolWorker) {
      return [
        GestureDetector(
          child: Container(
            width: 80,
            height: 80,
            child: Align(
              child: Image.asset('images/ic_change.png'),
            ),
          ),
          onTap: () => CommonUtils.pushRoute(
              viewService.context, RoutePath.patrolPlanListView),
          behavior: HitTestBehavior.translucent,
        )
      ];
    }

    if (state.userInfo.isCheckLeader) {
      return [
        GestureDetector(
          child: Container(
            width: 80,
            height: 80,
            child: Align(
              child: Image.asset('images/ic_change.png'),
            ),
          ),
          onTap: () =>
              dispatch(MainViewActionCreator.onSwitchCheckLeaderType()),
          behavior: HitTestBehavior.translucent,
        )
      ];
    }

    if (state.userInfo.isInstallWorker)
      return [
        GestureDetector(
          child: Container(
            width: 80,
            height: 80,
            margin: EdgeInsets.only(right: 8),
            child: Align(
              child: Text(
                '新增报装',
                style: TextThemeConfig.Font14WithColorWhite,
              ),
            ),
          ),
          onTap: () => dispatch(MainViewActionCreator.onNewInstall()),
          behavior: HitTestBehavior.translucent,
        )
      ];
    return [];
  }

  Widget _body() {
    if (state.userInfo.currentRoleName.length == 0) return MyLoadingWidget();
    if (state.countModel == null && state.userInfo.isCountLeader)
      return MyLoadingWidget();
    if (state.items == null && state.userInfo.isEngineer) {
      return MyLoadingWidget();
    }
    if (state.items == null && state.userInfo.isFixWorker) {
      return MyLoadingWidget();
    }

    if (state.installModel == null && state.userInfo.isInstallWorker)
      return MyLoadingWidget();

    if (state.model == null &&
        (state.userInfo.isCheckLeader || state.userInfo.isCheckWorker)) {
      return MyLoadingWidget();
    }

    if (state.model == null && state.userInfo.isPatrolWorker) {
      return MyLoadingWidget();
    }

    ///boss账号
    if (state.userInfo.isCountLeader) return _countLeaderWidget();

    ///报装账户
    if (state.userInfo.isInstallWorker) return _installWidget();
    int orderState = 0;
    if (state.userInfo.isEngineer) {
      orderState = state.sortIndex + 1;
      if (state.sortIndex == 2)  orderState = state.userInfo.isCustomer ? 9 : 4;
      if (state.sortIndex == 3) orderState = state.userInfo.isCustomer ? 4 : 5;
    }
    if (state.userInfo.isCheckWorker) {
      orderState = state.sortIndex;
    }
    if (state.userInfo.isFixWorker) {
      orderState = state.sortIndex + 1;
      if (state.sortIndex == 2) orderState = 4;
      if (state.sortIndex == 3) orderState = 5;
    }
      return Column(
      children: [
        (state.userInfo.isCheckLeader)
            ? Container()
            : Container(
                color: ThemeConfig.mainColor,
                child: MySearchWidget(
                  searchText: state.userInfo.isCheckLeader
                      ? '搜索安检员姓名/电话'
                      : state.userInfo.isPatrolWorker
                          ? '搜索片区'
                          : state.userInfo.isFixWorker
                              ? '搜索姓名/电话/地址'
                              : state.userInfo.isEngineer
                                  ? '搜索工单姓名/电话'
                                  : '搜索小区名',
                  type: state.userInfo.isCheckLeader
                      ? 1
                      : state.userInfo.isPatrolWorker
                          ? 6
                          : state.userInfo.isFixWorker
                              ? 8
                              : state.userInfo.isEngineer ? 12 : 3,
                  heroTag: 'MainSearch',
                  status: orderState,
                ),
              ),
        Expanded(
          child: CustomRefreshList(
            whiteBg: false,
            currentPage: state.currentPage,
            refreshController: state.refreshController,
            onRefresh: (_) => dispatch(MainViewActionCreator.onRefresh()),
            child: CustomScrollView(
              physics: NeverScrollableScrollPhysics(),
              slivers: [
                _topInfoWidget(),
                _sortWidget(),
                _itemWidget(),
              ],
            ),
          ),
        ),
        (state.multipleSelect && state.userInfo.isFixWorker)
            ? Container(
                color: Colors.white,
                height: 45,
                child: Row(
                  children: [
                    Padding(
                      padding: EdgeInsets.only(left: 15),
                      child: InkWell(
                        child: Row(
                          children: [
                            Container(
                              width: 20,
                              height: 20,
                              child: Image.asset((state.selectItems.length ==
                                          state.items.length &&
                                      state.items.length != 0)
                                  ? 'images/cricle_select.png'
                                  : 'images/circle.png'),
                            ),
                            Padding(
                              padding: EdgeInsets.only(left: 6),
                              child: Text(
                                '全选',
                                style: TextThemeConfig.Font14WithColor22,
                              ),
                            ),
                          ],
                        ),
                        onTap: () =>
                            dispatch(MainViewActionCreator.onSelectAll()),
                      ),
                    ),
                    Expanded(child: Container()),
                    Padding(
                      padding: EdgeInsets.only(right: 15),
                      child: InkWell(
                        child: Container(
                          width: 60,
                          height: 26,
                          decoration: BoxDecoration(
                            color: ThemeConfig.mainColor,
                            borderRadius: BorderRadius.all(Radius.circular(4)),
                          ),
                          child: Center(
                            child: Text(
                              '接单',
                              style: TextThemeConfig.Font12WithColorWhite,
                            ),
                          ),
                        ),
                        onTap: () =>
                            dispatch(MainViewActionCreator.onGetAllOrder()),
                      ),
                    ),
                  ],
                ),
              )
            : Container(),
      ],
    );
  }

  return MediaQuery(
    //设置文字大小不随系统设置改变
    data: MediaQuery.of(viewService.context).copyWith(textScaleFactor: 1.0),
    child: Scaffold(
      appBar: myAppBar(
        viewService.context,
        title: _title(),
        leading: Container(),
        actions: _actions(),
      ),
      body: _body(),
    ),
  );
}
